#!/bin/bash
# Version 2.2

usage(){
    echo "Usage : $0 <user mysql> <password>"
    exit 1;
}

if [ $# -lt 2 ]; then
    {
	usage
    }
fi

echo -e "************Installation des prérequis************\n"
sudo tasksel install lamp-server
sudo apt-get install texlive imagemagick

echo -e "************Installation de la base de données************\n"
echo "use mysql; create database latex_beamr;" | mysql --user=$1 --password=$2
mysql latex_beamr --user=$1 --password=$2 <$PWD/DB_CREATE.sql

echo -e "************Configuration de l'application************\n"
sed -i "s/root/$1/g" $PWD/system/application/config/database.php
sed -i "s/azerty/$2/g" $PWD/system/application/config/database.php
bash liste_theme.sh

echo -e "************Lancement de l'application************\n"
sudo rm /var/www/latex-beamr
sudo ln -s $PWD /var/www/latex-beamr
firefox http://localhost/latex-beamr&

exit 0;